package com.ews.onlineexchange.model.assess;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Formula;
import org.hibernate.validator.constraints.Length;

import com.ews.onlineexchange.enumType.RecordStatus;
import com.ews.onlineexchange.model.Attachment;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.Image;
import com.ews.onlineexchange.model.ServiceSupplier;

@Entity
public class AssessRecord extends DataEntity {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	
	private Dict				dict;
	private BigDecimal			score;
	private Date				assessDate;
	private ServiceSupplier     serviceSupplier;
	
	private Integer 			periodYear;
	private Integer				periodSeqNo;
	private boolean 			rolledback;

	private String				assessResult;
	private List<Image>			images				= new ArrayList<Image>();
	private List<Attachment>	attachments			= new ArrayList<Attachment>();
	private RecordStatus		recordStatus 		= RecordStatus.Initaling;
	private Integer 			intStatus;
	
	/*
	 * 是否已被覆盖
	 */
	private boolean 			override;
	
	@NotNull
	@ManyToOne
	public Dict getDict() {
		return dict;
	}

	public void setDict( Dict dict ) {
		this.dict = dict;
	}
	
	public BigDecimal getScore() {
		return score;
	}

	public void setScore( BigDecimal score ) {
		this.score = score;
	}

	@NotNull
	@Temporal( TemporalType.DATE )
	public Date getAssessDate() {
		return assessDate;
	}

	public void setAssessDate( Date assessDate ) {
		this.assessDate = assessDate;
	}

	@ManyToOne
	@NotNull
	public ServiceSupplier getServiceSupplier() {
		return serviceSupplier;
	}

	public void setServiceSupplier( ServiceSupplier serviceSupplier ) {
		this.serviceSupplier = serviceSupplier;
	}

	@Min( 2019L ) @Max( 3000L )
	@Column( scale = 4 )
	public Integer getPeriodYear() {
		return periodYear;
	}

	public void setPeriodYear( Integer periodYear ) {
		this.periodYear = periodYear;
	}

	@Min( 1L ) @Max( 12L )
	@Column( scale = 2 )
	public Integer getPeriodSeqNo() {
		return periodSeqNo;
	}

	public void setPeriodSeqNo( Integer periodSeqNo ) {
		this.periodSeqNo = periodSeqNo;
	}

	public boolean isRolledback() {
		return rolledback;
	}

	public void setRolledback( boolean rolledback ) {
		this.rolledback = rolledback;
	}

	@Length( max = 4000 )
	public String getAssessResult() {
		return assessResult;
	}

	public void setAssessResult( String assessResult ) {
		this.assessResult = assessResult;
	}
	
	@OneToMany(cascade =CascadeType.ALL)
	public List<Image> getImages() {
		return images;
	}

	public void setImages( List<Image> images ) {
		this.images = images;
	}
	
	@OneToMany(cascade = CascadeType.ALL)
	public List<Attachment> getAttachments() {
		return attachments;
	}

	public void setAttachments( List<Attachment> attachments ) {
		this.attachments = attachments;
	}
	
	@NotNull
	@Enumerated(EnumType.STRING)
	public RecordStatus getRecordStatus() {
		return recordStatus;
	}

	public void setRecordStatus(RecordStatus recordStatus) {
		this.recordStatus = recordStatus;
	}

	@Formula( "CASE recordStatus WHEN 'Initaling' THEN 0 WHEN 'Keeped' THEN 1 WHEN 'Deleted' THEN 2 END" )
	public Integer getIntStatus() {
		return intStatus;
	}

	public void setIntStatus( Integer intStatus ) {
		this.intStatus = intStatus;
	}

	public boolean isOverride() {
		return override;
	}

	public void setOverride( boolean override ) {
		this.override = override;
	}
	
	
}
